﻿@model List<TalentDesk.Contracts.Ef.Menu>

<ul id="menu">
    <li></li>
</ul>


<script> var menu = null;
    $(document).ready(function () {
        var menu = null;
        $(document).ready(function () {
            $("#menu").kendoMenu({ dataSource: @Html.Raw(Json.Encode(GetMenu(Model)))});
            });
        });
</script>

@functions
    {
    public class Menu
    {
        public string text { get; set; }
        public string url { get; set; }
        public string imageUrl { get; set; }
        public List<Menu> items { get; set; }
    }
    private List<Menu> GetMenu(List<TalentDesk.Contracts.Ef.Menu> items)
    {
        return items.Select(item => new Menu()
            {
                text = item.MenuName,
                url = item.Action != null ? String.Format("/{0}/{1}", item.Action.ControlName, item.Action.ActionName) : ""
                ,
                items = item.Menus1.Count != 0 ? GetMenu(item.Menus1.ToList()) : new List<Menu>()
            }).ToList();
    }
    }

